<template>
<view class="right_tab" :class="{showD:this.isShow }" @click="this.isShow = true" @touchstart="touchS" @touchmove.stop.prevent="touchM"  @touchend="touchE">
	<view class="r_item" @click="toPage('czzn')">
		<image class="img" src="../../static/image/czzn.png" mode=""></image>
		<view class="">操作指南</view>
	</view>
	<view class="line_div"></view>
	<view class="r_item" @click="toPage('zsPage',1)">
		<image class="img" src="https://wqq103910.oss-cn-hangzhou.aliyuncs.com/images/fuzhou/image/index/icon_r1.png" mode=""></image>
		<view class="">我要投资</view>
	</view>
	<view class="line_div"></view>
	<view class="r_item" @click="toPage('zsPage',2)">
		<image class="img" src="https://wqq103910.oss-cn-hangzhou.aliyuncs.com/images/fuzhou/image/index/icon_r1.png" mode=""></image>
		<view class="">我要招商</view>
	</view>
	<view class="line_div"></view>
	<view class="r_item" @click="toPage('dzmp',true)">
		<image class="img" src="https://wqq103910.oss-cn-hangzhou.aliyuncs.com/images/fuzhou/image/index/icon_r2.png" mode=""></image>
		<view class="">电子名片</view>
	</view>
	<view class="line_div" ></view>
	<!-- <view class="r_item" @click="toRx">
		<image class="img" src="https://wqq103910.oss-cn-hangzhou.aliyuncs.com/images/fuzhou/image/index/icon_r3.png" mode=""></image>
		<view class="">投资</view>
		<view class="">12345</view>
	</view> -->
	<shouquan ref="shouquan" @getInfo='getInfo'></shouquan>
</view>
</template>

<script>
	import shouquan from '@/components/shouquan/shouquan.vue'
	import {GetopenidByCode,CheckUserByOpenid,AddWxappUser} from'@/utils/api'
	export default {
		name:"right_xf",
		data() {
			return {
				start:{
					left:0,
					top:0
				},
				x:0,
				y:0,
				oldx:0,
				oldy:0,
				isMove:false,
				isShow:true
			};
		},
		created(){

		},
		components: {
			shouquan
		}, 
		methods:{
			toLogin(){
				let that = this
				uni.login({
					provider: 'weixin',
					success: function (res) {
						GetopenidByCode({code:res.code}).then(res=>{
							uni.setStorageSync('openid',res.data.openid)
							uni.setStorageSync('session_key',res.data.session_key)
							CheckUserByOpenid({openid:uni.getStorageSync('openid'),role_id:uni.getStorageSync('role_id')}).then(res=>{
								if(res.status == 0){
									that.$refs.shouquan.show()
								}else{ 
									uni.setStorageSync('userinfo', JSON.stringify(res.data))
									uni.setStorageSync('token',res.data.token)
									that.hasInfo=true
									that.info = JSON.parse(uni.getStorageSync('userinfo'))
								}
							})
						})
					}
				});
			},
			getInfo(data){
				AddWxappUser({openid:uni.getStorageSync('openid'),nickname:data.nickName, gender:data.gender, avatar:data.avatarUrl, role_id:uni.getStorageSync('role_id')}).then(res=>{
					this.info = res.data
					uni.setStorageSync('userinfo',JSON.stringify(this.info))
					uni.setStorageSync('token',this.info.token)
					this.hasInfo=true
					if(!this.info.mobile){
						
					}
				})
			},
			toPage(page,type){
				if(type==1||type==2){
					uni.navigateTo({
						url:`/pages/${page}/${page}?type_id=`+type
					})
					return
				}
				this.isCz = false
				if(type&&
					(!uni.getStorageSync('token')||!uni.getStorageSync('userinfo')||uni.getStorageSync('userinfo').length<=2 || uni.getStorageSync('userinfo')==null || uni.getStorageSync('userinfo')=='null')){
					this.toLogin()
					// uni.showModal({
					// 	title:'提示',
					// 	content:'该功能需要登录',
					// 	showCancel:true,
					// 	success:e=>{
					// 		if(e.confirm){
					// 			uni.switchTab({
					// 				url:'/pages/my/my'
					// 			})
					// 		}
					// 	}
					// })
					return
				}
				if(type=='subPage'){
					uni.navigateTo({
						url:`/subPage/pages/${page}/${page}`
					})
					return
				}
				uni.navigateTo({
					url:`/pages/${page}/${page}`
				})
			},
			toRx(){
				this.isCz = false
				uni.navigateTo({
					url:`/pages/gzRx/gzRx`
				})
			},
		  phone(){
				uni.makePhoneCall({
						phoneNumber: '0797-8996761' //仅为示例
				})
			},
			touchS(val){
				this.isMove=true
				this.start.left = val.changedTouches[0].clientX 
				this.start.top = val.changedTouches[0].clientY 
			},
			touchM(val){
				if(this.isMove==false){
					return
				}
				this.x = this.oldx + val.changedTouches[0].clientX  - this.start.left 
				this.y = this.oldy + val.changedTouches[0].clientY  - this.start.top 
				if(this.x>0){
					this.isShow = false
				}else{
					this.isShow = true
				}
			},
			touchE(val){
				this.x=0
				this.oldx=this.x
				this.oldy=this.y
				this.isMove=false
				
			},
		}
	}
</script>

<style scoped lang="scss">
.right_tab{
	position: fixed;
	right: -60px;
	bottom: 25%;
	width: 70px;
	border-radius: 10px 0 0 10px;
	background: linear-gradient(180deg,#C89F62cc,#876128ee);
	color: #fff;
	text-align: center;
	font-size: 11px;
	transition: all 0.5s;
	z-index: 1000;
	// padding: 10px 0;
	
	.r_item{
		margin: 10px;
	}
	.img{
		width: 26px;
		height: 26px;
		margin-bottom: 2px;
	}
}
.showD{
	right: 0px;
}
.line_div{
	height: 1px;
	width: 100%;
	background: #a4d8ff;
}

</style>